A high-performance Node.js utility designed to efficiently find and delete node_modules
directories across your system, helping you reclaim valuable disk space with minimal system impact.
Clean Node is a command-line tool that scans your file system for node_modules
directories and safely removes them. It's particularly useful for developers who work with multiple Node.js projects and want to free up disk space without manually hunting down each node_modules
folder.
# Quick start - scan and delete node_modules automatically
npx delete-nodes -y
# Or with confirmation prompt
npx delete-nodes
# Scan from a specific directory
npx delete-nodes /path/to/your/projects -y
# Clone the repository
git clone https://github.com/sarowarhosen03/clean-node.git
cd clean-node
# Make it executable
chmod +x index.js
# Run it
./index.js
npx delete-nodes [directory_path] [options]
Arguments:
directory_path
(optional): The starting directory to scan. Defaults to your home directory (~
)Options:
-y, --yes
: Automatically confirm deletion without prompting-h, --help
: Show help information (coming soon)Examples:
# Scan home directory with confirmation
npx delete-nodes
# Scan home directory and auto-delete
npx delete-nodes -y
# Scan specific directory with confirmation
npx delete-nodes ~/projects
# Scan specific directory and auto-delete
npx delete-nodes ~/projects -y
# This will scan your entire home directory for node_modules
npx delete-nodes
# Auto-delete without confirmation
npx delete-nodes -y
# Clean from your projects folder
npx delete-nodes ~/projects
# Clean from a specific project
npx delete-nodes ~/projects/my-app
# Clean from multiple locations (run multiple times)
npx delete-nodes ~/work-projects
npx delete-nodes ~/personal-projects
# Auto-delete from specific directories
npx delete-nodes ~/projects -y
# Test the tool on a small directory before running on your entire system
npx delete-nodes ~/test-directory
# Test with auto-delete
npx delete-nodes ~/test-directory -y
# Standard usage
npm start
# Development/testing mode
npm run dev
# Test mode
npm test
.
)Desktop
, Documents
, Downloads
, etc.).git
, .svn
).vscode
, .idea
)node_modules
directoriesnode_modules
node_modules
pathsfs.rm()
with recursive and force optionsfs.promises
for non-blocking file system operations// Automatically skips these directories
const SKIP_DIRS = new Set([
'Desktop', 'Documents', 'Downloads', 'Music',
'Pictures', 'Public', 'Templates', 'Videos'
]);
// Skips these patterns
const IGNORE_PATTERNS = [
/^\./, // Hidden files/directories
/^\.git$/, // Git directory
/^\.vscode$/, // VS Code settings
/^\.idea$/, // IntelliJ settings
];
node_modules
: Once a node_modules
directory is found, it's added to the deletion list and scanning stops inside itScanning for node_modules directories starting from: /home/user
This may take a while for large directory trees...
Scan completed in 1250ms
Found 15 node_modules directories
Directories to be deleted:
1. /home/user/project1/node_modules
2. /home/user/project2/node_modules
3. /home/user/old-project/node_modules
4. /home/user/work/project-a/node_modules
5. /home/user/work/project-b/node_modules
...
Do you want to delete these node_modules directories? (y/n): y
Starting deletion process...
Deleting 15/15: old-project/node_modules
โ
Successfully deleted 15 node_modules directories
๐ฆ Freed approximately 2.34 GB of disk space
โฑ๏ธ Deletion completed in 3200ms
Scanning for node_modules directories starting from: /home/user
โ ๏ธ Auto-confirmation enabled (-y flag)
This may take a while for large directory trees...
Scan completed in 1250ms
Found 15 node_modules directories
Directories to be deleted:
1. /home/user/project1/node_modules
2. /home/user/project2/node_modules
3. /home/user/old-project/node_modules
...
โ
Auto-confirming deletion (use without -y flag for manual confirmation)
Starting deletion process...
Deleting 15/15: old-project/node_modules
โ
Successfully deleted 15 node_modules directories
๐ฆ Freed approximately 2.34 GB of disk space
โฑ๏ธ Deletion completed in 3200ms
Scanning for node_modules directories starting from: /home/user
This may take a while for large directory trees...
Scan completed in 450ms
No node_modules directories found.
Found 8 node_modules directories
Directories to be deleted:
1. /home/user/project1/node_modules
2. /home/user/project2/node_modules
...
Do you want to delete these node_modules directories? (y/n): n
โ Operation cancelled.
// Graceful error handling for common issues
try {
await fs.rm(nodeModulesPath, { recursive: true, force: true });
} catch (error) {
console.warn(`Warning: Could not delete ${nodeModulesPath}: ${error.message}`);
}
clean-node/
โโโ index.js # Main application file
โโโ package.json # Project configuration
โโโ README.md # This documentation
# Start the application
npm start
# Run tests
npm test
# Development mode (test on specific directory)
npm run dev
package.json
files for projects you want to keepnode_modules
node_modules
directory itself (not the parent project)node_modules
directoriespackage.json
and package-lock.json
filesWe welcome contributions! Here's how you can help:
# Fork and clone the repository
git clone https://github.com/your-username/clean-node.git
cd clean-node
# Install dependencies (if any are added in the future)
npm install
# Make your changes
# Test thoroughly
npm test
# Submit a pull request
git checkout -b feature/amazing-feature
git commit -m 'Add amazing feature'
git push origin feature/amazing-feature
This project is licensed under the MIT License - see the LICENSE file for details.
Use at your own risk! This tool permanently deletes node_modules
directories. While it's designed to be safe, always ensure you can regenerate your dependencies before using this tool. The authors are not responsible for any data loss.
If you encounter any issues or have questions:
Happy cleaning! ๐งนโจ